<?php
namespace Mobile\Controller;
use Think\Controller;
class SeasonController extends Controller {
    public function index(){
        if(!empty($_GET['mvid'])){
            session('movi_id',$_GET['mvid']);
        }
        $_SESSION['mobile']['mid']=$_GET['mvid'];
        $mid=$_GET['mvid'];
        $this->assign('mid',$mid);
        $today=date('m-d',time());
        $tomorrow=date('m-d',(time()+86400));
        $acquired=date('m-d',(time()+172800));
        $weekarray=array("日","一","二","三","四","五","六");
        $week= $weekarray[date("w",(time()+259200))].date('m-d',(time()+259200));
        $this->assign('today',$today);
        $this->assign('tomorrow',$tomorrow);
        $this->assign('acquired',$acquired);
        $this->assign('week',$week);
        $model=D('Screening');
        switch($_GET['time']){
                case 1:
                    $mode=$model->setAll($today);
                    foreach($mode as $key =>$value){
                        $arr=$model->getAll($value,session('movi_id'));
                        if(!empty($arr)){
                            $data[$key]=$arr;
                            if($this->inarray($data,$arr['uid'])>1){
                                unset($data[$key]);
                                $a=$this->plases($data,$arr['uid']);
                                $data[$a]['time'].='|'.$arr['time'];
                            }
                        }
                    }
                   $this->assign('data',$data);
                    $this->assign('td',1);
                    break;
            case 2:
                $mode=$model->setAll($tomorrow);
                foreach($mode as $key =>$value){
                    $arr=$model->getAll($value,session('movi_id'));
                    if(!empty($arr)){
                        $data[$key]=$arr;
                        if($this->inarray($data,$arr['uid'])>1){
                              unset($data[$key]);
                            $a=$this->plases($data,$arr['uid']);
                            $data[$a]['time'].='|'.$arr['time'];
                        }
                    }
                }
                $this->assign('data',$data);
                    $this->assign('tm',1);
                break;
            case 3:
                $mode=$model->setAll($acquired);
                foreach($mode as $key =>$value){
                    $arr=$model->getAll($value,session('movi_id'));
                    if(!empty($arr)){
                        $data[$key]=$arr;
                        if($this->inarray($data,$arr['uid'])>1){
                            unset($data[$key]);
                            $a=$this->plases($data,$arr['uid']);
                            $data[$a]['time'].='|'.$arr['time'];
                        }
                    }
                }
                $this->assign('data',$data);
                $this->assign('ac',1);
                break;
            case 4:
                $time=date('m-d',(time()+259200));
                $mode=$model->setAll($time);
                foreach($mode as $key =>$value){
                    $arr=$model->getAll($value,session('movi_id'));
                    if(!empty($arr)){
                        $data[$key]=$arr;
                        if($this->inarray($data,$arr['uid'])>1){
                            unset($data[$key]);
                            $a=$this->plases($data,$arr['uid']);
                            $data[$a]['time'].='|'.$arr['time'];
                        }
                    }
                }
                $this->assign('data',$data);
                $this->assign('wk',1);
                break;
        }

        $this->display();
    }

    public function inarray($arr,$val){
        $b=[];
        foreach($arr as $key => $value){
            if($value['uid']==$val){
              $b[$key].=$val;
            }
        }
        return count($b);
    }

    public function plases($arr,$val){
        foreach($arr as $key =>$value){
            if($value['uid']==$val){
                return $key;
            }
        }
    }

    public function season()
    {
        $uname=$_GET;
        $mid=session('movi_id');
        $this->assign('mid',$mid);
        $id=$_GET['id'];
        $_SESSION['mobile']['uid']=$id;
        $today = date('m-d', time());
        $tomorrow = date('m-d', (time() + 86400));
        $acquired = date('m-d', (time() + 172800));
        $weekarray = array("日", "一", "二", "三", "四", "五", "六");
        $week = $weekarray[date("w", (time() + 259200))] . date('m-d', (time() + 259200));
        $this->assign('uname', $uname);
        $this->assign('today', $today);
        $this->assign('tomorrow', $tomorrow);
        $this->assign('acquired', $acquired);
        $this->assign('week', $week);
        $model = D('Screening');
        switch ($_GET['time']) {
            case 1:
                $mode=$model->setAll($today);
                foreach($mode as $key =>$value){
                    $arr=$model->arAll($id,$value,session('movi_id'));
                    if(!empty($arr)) {
                        $data[$key] = $arr;
                    }
                }
                $data=array_values($data);
                $this->assign('data',$data,session('movi_id'));
                $this->assign('td', 1);
                break;
            case 2:
                $this->assign('tm', 1);
                $mode=$model->setAll($tomorrow);
                foreach($mode as $key =>$value){
                    $arr=$model->arAll($id,$value,session('movi_id'));
                    if(!empty($arr)) {
                        $data[$key] = $arr;
                    }
                }
                $data=array_values($data);
                $this->assign('data',$data);
                break;
            case 3:
                $this->assign('ac', 1);
                $mode=$model->setAll($acquired);
                foreach($mode as $key =>$value){
                    $arr=$model->arAll($id,$value,session('movi_id'));
                    if(!empty($arr)) {
                        $data[$key] = $arr;

                    }
                }
                $data=array_values($data);
                $this->assign('data',$data);
                var_dump($data);
                break;
            case 4:
                $this->assign('wk', 1);
                $time=date('m-d',(time()+259200));
                $mode=$model->setAll($time);
                foreach($mode as $key =>$value){
                    $arr=$model->arAll($id,$value,session('movi_id'));
                    if(!empty($arr)) {
                        $data[$key] = $arr;
                        var_dump($data);
                    }
                }
                $data=array_values($data);
                $this->assign('data',$data);
                break;
        }
                $this->assign('id',$id);

                $this->display();
        }
}